<?php

class database{
    protected $db = "";
    protected $_result = "";
    
    function __construct() {
        $this->db = mysql_connect(config::HOST, config::USER, config::PASS) or die("Can't connect to database...");
        mysql_select_db(config::DATA,  $this->db) or die("Database is not exist");
        mysql_query("SET NAMES UTF8");
    }
    
    function query($sql){
        $this->_result = mysql_query($sql);
    }
    
    function num_rows(){
        if($this->_result){
            $rows = mysql_num_rows($this->_result);
        }else{
            $rows = 0;
        }
        return $rows;
    }
    
    function fetch(){
        if($this->_result){
            $data = mysql_fetch_assoc($this->_result);
        }
        return $data;
    }
    
    function fetchall(){
        $data = array();
        if($this->_result){
            while ($row = mysql_fetch_assoc($this->_result)){
                $data[] = $row;
            }
        }
        return $data;
    }
}